home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wstype / source / windmgr.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  5KB  |  291 lines

  1. /***   [windmgr.c]
  2. *
  3. *    ウィンドウ管理        (C)ささがわ
  4. *
  5. *    For GNU C Compiler (GCC)   Version 1.39
  6. *
  7. ***/
  8.  
  9. #include <stdlib.h>
  10. #include <mos.h>
  11. #include "graph.h"
  12. #include "windmgr.h"
  13. #include "txwind.h"
  14. #include "backg.h"
  15. #include "icn.h"
  16.  
  17. #define N_WINDOW    128
  18.  
  19. static struct wmgr_t    Winf[N_WINDOW];    /* ウィンドウ情報配列 */
  20. static int    nWind = 0, Curw = -1;        /* ウィンドウの数とカレント・ウィンドウ */
  21.  
  22. /* ウィンドウ新規登録関数 */
  23. /*   return -1:memory error  -2:file error  -3:too many window */
  24. int WMGR_regi(int sort, const char *path, struct RECT *xy1, struct RECT *xy2) {
  25.     void    *ptr;
  26.     
  27.     if (nWind >= 128)
  28.         return -3;
  29.     
  30.     switch (sort) {
  31.         int        r;
  32.         
  33.         default:
  34.             ICN_mos(1);
  35.             r = TXW_regi(path, (struct txinfo_t **)&ptr, xy1->x1, xy1->x2);
  36.             ICN_mos(0);
  37.             if (r)    return r;
  38.             break;
  39.     }
  40.     
  41.     Winf[nWind].sort = sort;
  42.     Winf[nWind].no = nWind;
  43.     Winf[nWind].cxy = *xy1;
  44.     Winf[nWind].pxy = *xy2;
  45.     Winf[nWind].inf = ptr;
  46.     nWind++;
  47.     
  48.     return (nWind - 1);
  49. }
  50.  
  51. void WMGR_place(int no, int total, int wx, int wy, struct RECT *xy) {
  52.     if (total <= 0 || (no < 0 || total <= no))
  53.         return;
  54.     
  55.     if (total <= 8) {
  56.         if (total == 1) {
  57.             xy->x1 = 0;        xy->y1 = 40;
  58.             xy->x2 = 639;    xy->y2 = 479;
  59.         } else if (total == 2) {
  60.             xy->x1 = 0;        xy->y1 = no ? 260 : 40;
  61.             xy->x2 = 639;    xy->y2 = xy->y1 + 219;
  62.         } else if (total <= 4) {
  63.             xy->x1 = no % 2 ? 320 : 0;
  64.             xy->y1 = no / 2 ? 260 : 40;
  65.             xy->x2 = xy->x1 + 319;
  66.             xy->y2 = xy->y1 + 219;
  67.         } else if (total <= 6) {
  68.             xy->x1 = no % 2 ? 320 : 0;
  69.             xy->y1 = 146 * (no / 2) + 40;
  70.             xy->x2 = xy->x1 + 319;
  71.             xy->y2 = xy->y1 + 145;
  72.         } else {
  73.             xy->x1 = no % 2 ? 320 : 0;
  74.             xy->y1 = 110 * (no / 2) + 40;
  75.             xy->x2 = xy->x1 + 319;
  76.             xy->y2 = xy->y1 + 109;
  77.         }
  78.         xy->x1 += wx;    xy->y1 += wy;
  79.         xy->x2 += wx;    xy->y2 += wy;
  80.     } else {
  81.         no %= 12;
  82.         xy->x1 = 341 * (no % 3);
  83.         xy->y1 = 118 * (no / 3) + 40;
  84.         xy->x2 = xy->x1 + 340;
  85.         xy->y2 = xy->y1 + 117;
  86.     }
  87. }
  88.  
  89. void WMGR_draw(int no) {
  90.     if (no < 0 || nWind <= no)
  91.         return;
  92.     
  93.     switch (Winf[no].sort) {
  94.         default:
  95.             TXW_draw(no);
  96.     }
  97. }
  98.  
  99. int WMGR_no(int no) {
  100.     if (no < 0)
  101.         no = Curw;
  102.     if (no < 0 || nWind <= no)
  103.         return -1;
  104.     
  105.     return Winf[no].no;
  106. }
  107.  
  108. /* ウィドウの大きさを返す関数 */
  109. void WMGR_cord(int no, struct RECT *xy) {
  110.     if (no < 0)
  111.         no = Curw;
  112.     if (no < 0 || nWind <= no)
  113.         return;
  114.     
  115.     *xy = Winf[no].cxy;
  116. }
  117.  
  118. /* カレント・ウィンドウを変更し描画する関数 */
  119. int WMGR_open(int m, int now, int wx, int wy) {
  120.     int        i;
  121.     struct wmgr_t    wm;
  122.     
  123.     if (now < 0 || nWind <= now)
  124.         return -1;
  125.     if (now == Curw)
  126.         return Curw;
  127.     
  128.     WMGR_close();
  129.     
  130.     if (!m)
  131.         m = WMGR_pile(now);
  132.     
  133.     wm = Winf[now];
  134.     for (i = now + 1; i < nWind; i++)
  135.         Winf[i - 1] = Winf[i];
  136.     Winf[nWind - 1] = wm;
  137.     Curw = nWind - 1;
  138.     
  139.     switch (Winf[Curw].sort) {
  140.         default:
  141.             TXW_open(!m, wx, wy);
  142.     }
  143.     
  144.     return Curw;
  145. }
  146.  
  147. /* ウィンドウ・マネージャーの情報提供関数 */
  148. void *WMGR_inf(int no) {
  149.     if (no < 0)
  150.         no = Curw;
  151.     
  152.     return (no < 0 || nWind <= no ? NULL : Winf[no].inf);
  153. }
  154.  
  155. int WMGR_pile(int no) {
  156.     int        i, ret = 0;
  157.     struct RECT    *p, *w;
  158.     
  159.     if (no < 0 || nWind <= no)
  160.         return 0;
  161.     
  162.     w = &Winf[no].cxy;
  163.     for (i = no + 1; i < nWind; i++) {
  164.         p = &Winf[i].cxy;
  165.         if (p->x2 >= w->x1 && w->x2 >= p->x1 && p->y2 >= w->y1 && w->y2 >= p->y1) {
  166.             ret = 1;
  167.             break;
  168.         }
  169.     }
  170.     
  171.     return ret;
  172. }
  173.  
  174. int WMGR_nWind(void) {
  175.     return nWind;
  176. }
  177.  
  178. int WMGR_cWind(void) {
  179.     return Curw;
  180. }
  181.  
  182. /* 現在位置がどのウィンドウ上にあるのかを返す関数 */
  183. int WMGR_onWind(int x, int y) {
  184.     int        i, ret = -1;
  185.     struct RECT    *p;
  186.     
  187.     for (i = nWind - 1; i >= 0; i--) {
  188.         p = &Winf[i].cxy;
  189.         if (p->x1 <= x && x <= p->x2 && p->y1 <= y && y <= p->y2) {
  190.             ret = i;
  191.             break;
  192.         }
  193.     }
  194.     
  195.     return ret;
  196. }
  197.  
  198. /* ウィンドウ削除関数 */
  199. void WMGR_unregi(int n) {
  200.     int        i, a;
  201.     
  202.     if (n < 0)
  203.         n = Curw;
  204.     if (n < 0 || nWind <= n)
  205.         return;
  206.     
  207.     free(Winf[n].inf);
  208.     a = Winf[n].no;
  209.     
  210.     for (i = n + 1; i < nWind; i++)
  211.         Winf[i - 1] = Winf[i];
  212.     Curw = -1;
  213.     nWind--;
  214.     
  215.     for (i = 0; i < nWind; i++) {
  216.         if (Winf[i].no > a)
  217.             Winf[i].no--;
  218.     }
  219. }
  220.  
  221. /* ウィンドウをクローズする関数 */
  222. void WMGR_close(void) {
  223.     if (Curw < 0)
  224.         return;
  225.     
  226.     switch (Winf[Curw].sort) {
  227.         default:
  228.             TXW_close();
  229.     }
  230.     Curw = -1;
  231. }
  232.  
  233. void WMGR_vanish(int a, int wx, int wy) {
  234.     int        i, w;
  235.     struct RECT    c, *p;
  236.     
  237.     w = a < 0 ? Curw : a;
  238.     if (w < 0 || nWind <= w)
  239.         return;
  240.     
  241.     WMGR_cord(w, &c);
  242.     MOS_disp(0);
  243.     EGB_view(c.x1, c.y1, c.x2, c.y2);
  244.     BACKG_draw(wx, wy);
  245.     for (i = 0; i < nWind; i++) {
  246.         p = &Winf[i].cxy;
  247.         if (i == w || p->x2 < c.x1 || c.x2 < p->x1 || p->y2 < c.y1 || c.y2 < p->y1)
  248.             continue;
  249.         
  250.         switch (Winf[i].sort) {
  251.             default:
  252.                 TXW_draw(i);
  253.         }
  254.     }
  255.     EGB_view(0, 0, 1023, 511);
  256.     MOS_disp(1);
  257.     
  258.     if (a < -1)
  259.         Curw = -1;
  260. }
  261.  
  262. /* ウィンドウの大きさ変更関数 */
  263. void WMGR_change(int n, struct RECT *c) {
  264.     if (n < 0)
  265.         n = Curw;
  266.     if (n < 0 || nWind <= n)
  267.         return;
  268.     
  269.     Winf[n].pxy = Winf[n].cxy;
  270.     Winf[n].cxy = *c;
  271. }
  272.  
  273. /* 過去のウィドウの大きさを返す関数 */
  274. void WMGR_pcord(int no, struct RECT *xy) {
  275.     if (no < 0)
  276.         no = Curw;
  277.     if (no < 0 || nWind <= no)
  278.         return;
  279.     
  280.     *xy = Winf[no].pxy;
  281. }
  282.  
  283. void WMGR_main(int x, int y) {
  284.     if (Curw < 0)
  285.         return;
  286.     
  287.     switch (Winf[Curw].sort) {
  288.         default:    TXW_main(x, y);    break;
  289.     }
  290. }
  291.